// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava.model;

import org.objectweb.asm.Opcodes;

public class FieldDefinition extends Field {

	public FieldDefinition(
			JavaClass declaringClass, 
			String name,
			TypeReference type,
			int access,
			String signature) {
		super(declaringClass, name, type);
		this.access = access;
		this.signature = signature;
	}

	private int access;
	
	private String signature;
	
	public int getAccess()
	{
		return this.access;
	}
	
	public String getSignature()
	{
		return this.signature;
	}
	
	public boolean isStatic()
	{
		return (access & Opcodes.ACC_STATIC) != 0;
	}
	
	public boolean isFinal()
	{
		return (access & Opcodes.ACC_FINAL) != 0;
	}
	
	public boolean isVolatile()
	{
		return (access & Opcodes.ACC_VOLATILE) != 0;
	}
	
	public boolean isTransient()
	{
		return (access & Opcodes.ACC_TRANSIENT) != 0;
	}
	
	@Override
	public boolean equals(Object o) {
		if (!this.getClass().isInstance(o))
			return super.equals(o);
		FieldDefinition other = (FieldDefinition)o;
		return super.equals(o) && other.access == this.access &&
			(this.signature == null ? other.signature == null :
				this.signature.equals(other.signature));
	}
	
	@Override
	public String toString()
	{
		return super.toString() + " " + this.getAccess() + " " + this.getSignature();
	}
}
